//
//  CYUserAccount.swift
//  WeiBo
//
//  Created by Mr_J on 16/3/6.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class CYUserAccount: NSObject,NSCoding {

    
    var uid: String?
    
    var expires_in: Double = 0 {
        didSet{
            expiresDate = NSDate().dateByAddingTimeInterval(expires_in)
        }
    }
    
    var expiresDate: NSDate?
    
    var access_token: String?
    
    var remind_in: String?
    
    var screen_name: String?
    
    var avatar_large: String?
    
    init(dict: [String : AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
    //public func encodeWithCoder(aCoder: NSCoder)
    //public init?(coder aDecoder: NSCoder) // NS_DESIGNATED_INITIALIZER
    
    
    func encodeWithCoder(encoder:NSCoder) {
        
        encoder.encodeObject(uid, forKey: "uid")
        encoder.encodeObject(access_token, forKey: "access_token")
        encoder.encodeObject(remind_in, forKey: "remind_in")
        encoder.encodeObject(screen_name, forKey: "screen_name")
        encoder.encodeObject(avatar_large, forKey: "avatar_large")
        encoder.encodeDouble(expires_in, forKey: "expires_in")
        encoder.encodeObject(expiresDate, forKey: "expiresDate")
    }
    required init?(coder decoder: NSCoder) {
        uid = decoder.decodeObjectForKey("uid") as? String
        access_token = decoder.decodeObjectForKey("access_token") as? String
        remind_in = decoder.decodeObjectForKey("remind_in") as? String
        screen_name = decoder.decodeObjectForKey("screen_name") as? String
        avatar_large = decoder.decodeObjectForKey("avatar_large") as? String
        expires_in = decoder.decodeDoubleForKey("expires_in")
        expiresDate = decoder.decodeObjectForKey("expiresDate") as? NSDate
    }

       override var description: String {
            let keys = ["uid","expires_in","access_token"]
            return dictionaryWithValuesForKeys(keys).description
        }
   
}
